package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @Override
    public List<NursingLevelVo> showAllNursingLevel() {
        return nursingLevelMapper.selectAllNursingLevel();
    }

    /**
     * 分页条件查询护理等级
     *
     * @param pageName
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> queryPage(Integer pageName, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageName, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.queryPage(name, status);
        return PageResponse.of(page, NursingLevelVo.class);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo showNursingLevelById(Integer id) {
        return nursingLevelMapper.selectNursingLevelById(id);
    }

    /**
     * 新增护理等级
     * @param nursingLevelDto
     */
    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insterNursingLevel(nursingLevel);
    }

    /**
     * 修改护理等级
     * @param nursingLevelDto
     */
    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    /**
     * 根据id删除护理等级
     * @param id
     */
    @Override
    public void deleteNursingLevelById(Integer id) {
        nursingLevelMapper.deleteNursingLevelById(id);
    }

    /**
     * 启用禁用护理等级
     * @param id
     * @param status
     */
    @Override
    public void updateNursingLevelStatusById(Integer id, Integer status) {
        nursingLevelMapper.updateNursingLevelStatusById(id,status);
    }
}
